package com.fcl.oschina.define.behavior;

import android.content.Context;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import com.fcl.mylibrary.util.FLog;
import com.fcl.oschina.R;
import com.fcl.oschina.util.DeviceUtil;


/**
 * Created by Administrator on 2017/2/16.
 */

public class VisibleBehavior extends CoordinatorLayout.Behavior<LinearLayout> {

    private String TAG = "VisibleBehavior";

    public VisibleBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, LinearLayout child, View dependency) {
        boolean result = (dependency instanceof AppBarLayout) && (dependency.getId() == R.id.visible_depend);
        return result;
    }

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, LinearLayout child, View dependency) {
        FLog.error(TAG, "bottom:"+dependency.getBottom()+"  base:"+DeviceUtil.dp2px(56));
        if (dependency.getBottom() <= DeviceUtil.dp2px(56)) {
            child.setVisibility(View.VISIBLE);
        } else {
            child.setVisibility(View.GONE);
        }
        return true;
    }
}
